package com.lori.search.service.imp;

import org.apache.solr.client.solrj.SolrQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.lori.search.dao.SolrDao;
import com.lori.search.pojo.SolrResult;
import com.lori.search.service.SolrService;
@Service
public class SolrServiceimp implements SolrService {
	@Autowired
	private SolrDao solrDaoimp;
	@Override
	public SolrResult search(String queryString, int page, int rows) throws Exception {
		//封装solrquery对象
		SolrQuery solrquery = new SolrQuery();
		//设置查询条件
		solrquery.setQuery(queryString);
		//设置分页信息
		solrquery.setStart(((page-1)*rows)).setRows(rows);
		//设置高亮
		solrquery.setHighlight(true).setHighlightSimplePre("<em style='color:red'>").setHighlightSimplePost("</em>");
		//设置搜索区域
		solrquery.set("df", "item_keywords");
		//执行结果
		SolrResult search = solrDaoimp.search(solrquery);
		//计算总页数
		int total = search.getTotal();
		int pageTotal = (int) Math.ceil(total/rows);
		search.setPageTotal(pageTotal);
		search.setPage(page);
		search.setRows(rows);
		return search;
	}

}
